package com.itheima.travel.service.impl;

import com.itheima.travel.dao.CategoryDao;
import com.itheima.travel.domain.Category;
import com.itheima.travel.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private CategoryDao categoryDao;

    @Override
    public List<Category> findAll() {
        List<Category> categories = (List<Category>) redisTemplate.opsForValue().get("categories");
        if (categories==null){
            categories = categoryDao.findAll();
            redisTemplate.opsForValue().set("categories",categories);
        }
        return categories;
    }
}
